package Thread;

public class Demo20 {
    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
           try{
               System.out.println("t1线程等待中,在wait之前");
               synchronized (locker){
                   locker.wait();
               }

           }catch ( InterruptedException e){
              throw new RuntimeException();
           }
            System.out.println("t1线程结束，在wait之后");
        });
        t1.start();
    }
    public static void main2(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
            synchronized(locker){
                System.out.println("t1线程在等待中,wait之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1线程等待结束，wait之后");
            }
        });
        t1.start();
    }
    public static void main1(String[] args) throws InterruptedException {
        Object locker = new Object();
        synchronized(locker){
            System.out.println("main线程等待中");
            locker.wait();
            System.out.println("main线程等待结束");
        }
    }
}
